--- Created by cy.
--- DateTime: 2021/3/13 17:18

json = require("GetData/json")
Exec = {}
--json转table
function Exec:Json2Table(jsonTree)
    if type(jsonTree) ~= "string" then
        error("Json2Table must be string")
        return {}
    end
    --decode解码函数
    local tbValue = json.decode(jsonTree) or {}
    return tbValue
end

--table转json
function Exec:Table2Json(tbValue)
    if type(tbValue) ~= "table" then
        error("Table2Json must be table")
        return {}
    end
    local jsonTree = json.encode(tbValue) or {}
    return jsonTree
end

--json数据获取(IO流)
function Exec:GetFile(fileName)
    local filePath = "C:/Users/dell/Desktop/" .. fileName
    local table = {}
    if filePath ~= nil and type(filePath) == "string" then
        local file = io.open(filePath, "r")
        local jsonTree = file:read("*a")
        table = Exec:Json2Table(jsonTree)
    end
    return table
end



